﻿using CL.Enum.Common;
using CL.Game.BLL.View;
using CL.Json.Entity;
using CL.Tools.Common;
using CL.WebAPI.Filters;
using System;
using System.Threading.Tasks;
using System.Web.Http;
using WebAPI.Models;

namespace CL.WebAPI.Controllers
{
    public class SpecialController : BaseController
    {
        [HttpPost, DataLog, ErrorLog, VerifySecret, ActionName("SpecialBet")]
        public async Task<string> SpecialBet()
        {
            JsonResult result = null;
            try
            {
                if (DataSecret.VerifyRec == (int)ResultCode.Success)
                {
                    var dic = DataSecret.DicPostPara;
                    long UserCode = 0;                                        //用户编码
                    int LotteryCode = 0;                                      //彩种编码
                    short BuyType = 0;                                        //投注类型 0标准投注 1追号投注 2跟单投注
                    long Amount = 0;                                          //投注金额
                    string IsuseNum = dic["IsuseNum"].ToString();             //期号
                    string BeginTime = dic["BeginTime"].ToString();           //开始时间
                    string EndTime = dic["EndTime"].ToString();               //结束时间
                    string RoomCode = dic["RoomCode"].ToString();             //聊天室编号
                    string BetData = dic["BetData"].ToString();               //投注内容
                    long.TryParse(dic["UserCode"].ToString(), out UserCode);
                    int.TryParse(dic["LotteryCode"].ToString(), out LotteryCode);
                    short.TryParse(dic["BuyType"].ToString(), out BuyType);
                    long.TryParse(dic["Amount"].ToString(), out Amount);
                    result = new udv_SpecialBLL().SpecialBet(UserCode, LotteryCode, IsuseNum, BeginTime, EndTime, BuyType, Amount, RoomCode, BetData);
                }
                else
                    result = new JsonResult()
                    {
                        Code = DataSecret.VerifyRec,
                        Msg = Common.GetDescription((ResultCode)DataSecret.VerifyRec)
                    };
            }
            catch (Exception ex)
            {
                new Log("SpecialController").Write("投注错误[SpecialBet]：" + ex.Message, true);
                result = new JsonResult()
                {
                    Code = (int)ResultCode.SystemBusy,
                    Msg = Common.GetDescription(ResultCode.SystemBusy)
                };
            }
            return await base.TResultAsync(result);
        }
    }
}
